package com.atguigu.rabbitmq.six;

import com.atguigu.rabbitmq.util.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

public class ReceiveLogsDirect01 {

    public static final String EXCHANGE_NAME = "direct_logs";


    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();

        // 声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        // 声明一个队列
        channel.queueDeclare("console",false,false,false,null);

        // 绑定队列和交换机,可有多重绑定
        channel.queueBind("console",EXCHANGE_NAME,"info");
        channel.queueBind("console",EXCHANGE_NAME,"warning");

        System.out.println("ReceiveLogsDirect01等待接受消息，吧接受到的消息打印到屏幕上。。。。");

        // 接受消息
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("ReceiveLogsDirect01控制台打印接受到消息："+new String(message.getBody(),"UTF-8"));
        };

        // 消费者消费消息时的回调
        channel.basicConsume("console",true,deliverCallback, consumerTag->{} );
    }
}